/*     */ package org.jeecgframework.p3.cg.factory;
/*     */ 
/*     */ import freemarker.template.Configuration;
/*     */ import freemarker.template.DefaultObjectWrapper;
/*     */ import java.io.File;
/*     */ import java.io.PrintStream;
/*     */ import java.net.URL;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ import org.apache.velocity.VelocityContext;
/*     */ import org.jeecgframework.p3.cg.ColumnData;
/*     */ import org.jeecgframework.p3.cg.CommonPageParser;
/*     */ import org.jeecgframework.p3.cg.CreateBean;
/*     */ import org.jeecgframework.p3.cg.def.CodeResourceUtil;
/*     */ import org.jeecgframework.p3.cg.def.FreemarkerEngine;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CodeGenerateFactory
/*     */ {
/*  35 */   private static final Log log = LogFactory.getLog(CodeGenerateFactory.class);
/*  36 */   private static String url = CodeResourceUtil.URL;
/*  37 */   private static String username = CodeResourceUtil.USERNAME;
/*  38 */   private static String passWord = CodeResourceUtil.PASSWORD;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  44 */   private static String buss_package = CodeResourceUtil.bussiPackage;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void codeGenerateByVM(String tableName, String codeName, String keyType)
/*     */   {
/*     */     try
/*     */     {
/*  58 */       CreateBean createBean = new CreateBean();
/*  59 */       createBean.setMysqlInfo(url, username, passWord);
/*     */       
/*  61 */       String className = createBean.getTablesNameToClassName(tableName);
/*  62 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/*  63 */       String tableNameUpper = tableName.toUpperCase();
/*  64 */       String tablesAsName = createBean.getTablesASName(tableName);
/*  65 */       if (StringUtils.isEmpty(codeName)) {
/*  66 */         Map<String, String> tableCommentMap = createBean.getTableCommentMap();
/*  67 */         codeName = (String)tableCommentMap.get(tableNameUpper);
/*     */       }
/*  69 */       String sqlmapPathSrc = CodeResourceUtil.getConfigInfo("sqlmap_path_src");
/*  70 */       String domainPathSrc = CodeResourceUtil.getConfigInfo("domain_path_src");
/*  71 */       String daoPathSrc = CodeResourceUtil.getConfigInfo("dao_path_src");
/*  72 */       String daoImplPathSrc = CodeResourceUtil.getConfigInfo("dao_impl_path_src");
/*  73 */       String managerPathSrc = CodeResourceUtil.getConfigInfo("manager_path_src");
/*  74 */       String managerImplPathSrc = CodeResourceUtil.getConfigInfo("manager_impl_path_src");
/*  75 */       String servicePathSrc = CodeResourceUtil.getConfigInfo("service_path_src");
/*  76 */       String serviceImplPathSrc = CodeResourceUtil.getConfigInfo("service_impl_path_src");
/*     */       
/*  78 */       String sqlmapPackage = CodeResourceUtil.getConfigInfo("sqlmap_path");
/*  79 */       String domainPackage = CodeResourceUtil.getConfigInfo("domain_path");
/*  80 */       String daoPackage = CodeResourceUtil.getConfigInfo("dao_path");
/*  81 */       String daoImplPackage = CodeResourceUtil.getConfigInfo("dao_impl_path");
/*  82 */       String managerPackage = CodeResourceUtil.getConfigInfo("manager_path");
/*  83 */       String managerImplPackage = CodeResourceUtil.getConfigInfo("manager_impl_path");
/*  84 */       String servicePackage = CodeResourceUtil.getConfigInfo("service_path");
/*  85 */       String serviceImplPackage = CodeResourceUtil.getConfigInfo("service_impl_path");
/*     */       
/*     */ 
/*  88 */       String sqlMapperPath = sqlmapPackage.replace(".", "\\") + "\\" + tableNameUpper + ".xml";
/*  89 */       String domainPath = domainPackage.replace(".", "\\") + "\\" + className + ".java";
/*  90 */       String daoPath = daoPackage.replace(".", "\\") + "\\" + className + "Dao.java";
/*  91 */       String daoImplPath = daoImplPackage.replace(".", "\\") + "\\" + className + "DaoImpl.java";
/*  92 */       String managerPath = managerPackage.replace(".", "\\") + "\\" + className + "Manager.java";
/*  93 */       String managerImplPath = managerImplPackage.replace(".", "\\") + "\\" + className + "ManagerImpl.java";
/*  94 */       String servicePath = servicePackage.replace(".", "\\") + "\\" + className + "Service.java";
/*  95 */       String serviceImplPath = serviceImplPackage.replace(".", "\\") + "\\" + className + "ServiceImpl.java";
/*     */       
/*  97 */       String sqlMapperFlag = CodeResourceUtil.getConfigInfo("sqlmap_flag");
/*  98 */       String domainFlag = CodeResourceUtil.getConfigInfo("domain_flag");
/*  99 */       String daoFlag = CodeResourceUtil.getConfigInfo("dao_flag");
/* 100 */       String daoImplFlag = CodeResourceUtil.getConfigInfo("dao_impl_flag");
/* 101 */       String managerFlag = CodeResourceUtil.getConfigInfo("manager_flag");
/* 102 */       String managerImplFlag = CodeResourceUtil.getConfigInfo("manager_impl_flag");
/* 103 */       String serviceFlag = CodeResourceUtil.getConfigInfo("service_flag");
/* 104 */       String serviceImplFlag = CodeResourceUtil.getConfigInfo("service_impl_flag");
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 109 */       VelocityContext context = new VelocityContext();
/* 110 */       context.put("className", className);
/* 111 */       context.put("lowerName", lowerName);
/* 112 */       context.put("codeName", codeName);
/* 113 */       context.put("tableName", tableName);
/* 114 */       context.put("tableNameUpper", tableNameUpper);
/* 115 */       context.put("tablesAsName", tablesAsName);
/* 116 */       context.put("bussPackage", buss_package);
/* 117 */       context.put("domainPackage", domainPackage);
/* 118 */       context.put("daoPackage", daoPackage);
/* 119 */       context.put("daoImplPackage", daoImplPackage);
/* 120 */       context.put("managerPackage", managerPackage);
/* 121 */       context.put("managerImplPackage", managerImplPackage);
/* 122 */       context.put("servicePackage", servicePackage);
/* 123 */       context.put("serviceImplPackage", serviceImplPackage);
/* 124 */       context.put("keyType", keyType);
/*     */       
/*     */ 
/* 127 */       context.put("feilds", createBean.getBeanFeilds(tableName, className));
/*     */       
/*     */ 
/* 130 */       Map<String, Object> sqlMap = createBean.getAutoCreateSql(tableName);
/* 131 */       List<ColumnData> columnDatas = createBean.getColumnDatas(tableName);
/* 132 */       context.put("columnDatas", columnDatas);
/* 133 */       List<ColumnData> columnKeyDatas = createBean.getColumnKeyDatas(columnDatas);
/* 134 */       context.put("columnKeyDatas", columnKeyDatas);
/* 135 */       context.put("SQL", sqlMap);
/*     */       
/*     */ 
/* 138 */       if ("Y".equals(sqlMapperFlag)) {
/* 139 */         CommonPageParser.WriterPage(context, "sqlmap.vm", sqlmapPathSrc, sqlMapperPath);
/*     */       }
/* 141 */       if ("Y".equals(domainFlag)) {
/* 142 */         CommonPageParser.WriterPage(context, "domainClass.vm", domainPathSrc, domainPath);
/*     */       }
/* 144 */       if ("Y".equals(daoFlag)) {
/* 145 */         CommonPageParser.WriterPage(context, "daoClass.vm", daoPathSrc, daoPath);
/*     */       }
/* 147 */       if ("Y".equals(daoImplFlag)) {
/* 148 */         CommonPageParser.WriterPage(context, "daoImplClass.vm", daoImplPathSrc, daoImplPath);
/*     */       }
/* 150 */       if ("Y".equals(managerFlag)) {
/* 151 */         CommonPageParser.WriterPage(context, "managerClass.vm", managerPathSrc, managerPath);
/*     */       }
/* 153 */       if ("Y".equals(managerImplFlag)) {
/* 154 */         CommonPageParser.WriterPage(context, "managerImplClass.vm", managerImplPathSrc, managerImplPath);
/*     */       }
/* 156 */       if ("Y".equals(serviceFlag)) {
/* 157 */         CommonPageParser.WriterPage(context, "serviceClass.vm", servicePathSrc, servicePath);
/*     */       }
/* 159 */       if ("Y".equals(serviceImplFlag)) {
/* 160 */         CommonPageParser.WriterPage(context, "serviceImplClass.vm", serviceImplPathSrc, serviceImplPath);
/*     */       }
/* 162 */       log.info("----------------------------代码生成完毕---------------------------");
/* 163 */       System.out.println("----------------------------代码生成完毕---------------------------");
/*     */     } catch (Exception e1) {
/* 165 */       e1.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void codeGenerateByFTL(String tableName, String codeName, String keyType)
/*     */   {
/*     */     try
/*     */     {
/* 179 */       CreateBean createBean = new CreateBean();
/* 180 */       createBean.setMysqlInfo(url, username, passWord);
/*     */       
/* 182 */       String className = createBean.getTablesNameToClassName(tableName);
/* 183 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 184 */       String tableNameUpper = tableName.toUpperCase();
/* 185 */       String tablesAsName = createBean.getTablesASName(tableName);
/* 186 */       if (StringUtils.isEmpty(codeName)) {
/* 187 */         Map<String, String> tableCommentMap = createBean.getTableCommentMap();
/* 188 */         codeName = (String)tableCommentMap.get(tableNameUpper);
/*     */       }
/*     */       
/*     */ 
/* 192 */       String pathSrc = CodeResourceUtil.getConfigInfo("path_src");
/* 193 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 194 */       String bussiPackage = CodeResourceUtil.getConfigInfo("bussi_package");
/* 195 */       String author = CodeResourceUtil.getConfigInfo("author");
/* 196 */       String baseDao = CodeResourceUtil.getConfigInfo("baseDao");
/*     */       
/* 198 */       String sqlmapPackage = basePackage + "." + bussiPackage + ".sqlmap";
/* 199 */       String domainPackage = basePackage + "." + bussiPackage + ".entity";
/* 200 */       String daoPackage = basePackage + "." + bussiPackage + ".dao";
/* 201 */       String daoImplPackage = basePackage + "." + bussiPackage + ".dao.impl";
/* 202 */       String servicePackage = basePackage + "." + bussiPackage + ".service";
/* 203 */       String serviceImplPackage = basePackage + "." + bussiPackage + ".service.impl";
/* 204 */       String controllerPackage = basePackage + "." + bussiPackage + ".web.back";
/* 205 */       String domainQueryPackage = basePackage + "." + bussiPackage + ".vo";
/*     */       
/* 207 */       String pagePackage = "content." + bussiPackage + ".back";
/*     */       
/*     */ 
/* 210 */       String sqlMapperPath = sqlmapPackage.replace(".", "//") + "//" + className + ".xml";
/* 211 */       String domainPath = domainPackage.replace(".", "//") + "//" + className + ".java";
/* 212 */       String daoPath = daoPackage.replace(".", "//") + "//" + className + "Dao.java";
/* 213 */       String daoImplPath = daoImplPackage.replace(".", "//") + "//" + className + "DaoImpl.java";
/* 214 */       String servicePath = servicePackage.replace(".", "//") + "//" + className + "Service.java";
/* 215 */       String serviceImplPath = serviceImplPackage.replace(".", "//") + "//" + className + "ServiceImpl.java";
/* 216 */       String controllerPath = controllerPackage.replace(".", "//") + "//" + className + "Controller.java";
/* 217 */       String domainQueryPath = domainQueryPackage.replace(".", "//") + "//" + className + "Vo.java";
/*     */       
/* 219 */       String pageIndexPath = pagePackage.replace(".", "//") + "//" + lowerName + "-list.vm";
/* 220 */       String pageAddPath = pagePackage.replace(".", "//") + "//" + lowerName + "-add.vm";
/* 221 */       String pageEditPath = pagePackage.replace(".", "//") + "//" + lowerName + "-edit.vm";
/* 222 */       String pageDetailPath = pagePackage.replace(".", "//") + "//" + lowerName + "-detail.vm";
/*     */       
/*     */ 
/*     */ 
/* 226 */       String sqlMapperFlag = CodeResourceUtil.getConfigInfo("sqlmap_flag");
/* 227 */       String domainFlag = CodeResourceUtil.getConfigInfo("domain_flag");
/* 228 */       String daoFlag = CodeResourceUtil.getConfigInfo("dao_flag");
/* 229 */       String daoImplFlag = CodeResourceUtil.getConfigInfo("dao_impl_flag");
/* 230 */       String serviceFlag = CodeResourceUtil.getConfigInfo("service_flag");
/* 231 */       String serviceImplFlag = CodeResourceUtil.getConfigInfo("service_impl_flag");
/* 232 */       String controllerFlag = CodeResourceUtil.getConfigInfo("controller_flag");
/* 233 */       String domainQueryFlag = CodeResourceUtil.getConfigInfo("domain_query_flag");
/*     */       
/* 235 */       String pageFlag = CodeResourceUtil.getConfigInfo("page_flag");
/*     */       
/* 237 */       Map<String, Object> sqlMap = createBean.getAutoCreateSql(tableName);
/* 238 */       List<ColumnData> columnDatas = createBean.getColumnDatas(tableName);
/* 239 */       List<ColumnData> columnKeyDatas = createBean.getColumnKeyDatas(columnDatas);
/* 240 */       String columnKeyParam = createBean.getColumnKeyParam(columnKeyDatas);
/* 241 */       String columnKeyUseParam = createBean.getColumnKeyUseParam(columnKeyDatas);
/* 242 */       SimpleDateFormat dateformat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");
/* 243 */       String nowDate = dateformat.format(new Date());
/* 244 */       System.out.println("时间:" + nowDate);
/*     */       
/* 246 */       Map<String, Object> root = new HashMap();
/* 247 */       root.put("author", author);
/* 248 */       root.put("baseDao", baseDao);
/* 249 */       root.put("className", className);
/* 250 */       root.put("lowerName", lowerName);
/* 251 */       root.put("codeName", codeName);
/* 252 */       root.put("tableName", tableName);
/* 253 */       root.put("tableNameUpper", tableNameUpper);
/* 254 */       root.put("tablesAsName", tablesAsName);
/* 255 */       root.put("bussPackage", bussiPackage);
/* 256 */       root.put("domainPackage", domainPackage);
/* 257 */       root.put("domainQueryPackage", domainQueryPackage);
/* 258 */       root.put("daoPackage", daoPackage);
/* 259 */       root.put("daoImplPackage", daoImplPackage);
/* 260 */       root.put("servicePackage", servicePackage);
/* 261 */       root.put("serviceImplPackage", serviceImplPackage);
/* 262 */       root.put("controllerPackage", controllerPackage);
/*     */       
/* 264 */       root.put("keyType", keyType);
/* 265 */       root.put("nowDate", nowDate);
/*     */       
/* 267 */       root.put("feilds", createBean.getBeanFeilds(tableName, className));
/* 268 */       root.put("queryfeilds", createBean.getQueryBeanFeilds(tableName, className));
/*     */       
/*     */ 
/* 271 */       root.put("columnDatas", columnDatas);
/* 272 */       root.put("columnKeyDatas", columnKeyDatas);
/* 273 */       root.put("columnKeyParam", columnKeyParam);
/* 274 */       root.put("columnKeyUseParam", columnKeyUseParam);
/* 275 */       root.put("SQL", sqlMap);
/*     */       
/*     */ 
/* 278 */       Configuration cfg = new Configuration();
/* 279 */       String templateBasePath = getClassPath() + CodeResourceUtil.getConfigInfo("templatepath_ftl");
/* 280 */       cfg.setDirectoryForTemplateLoading(new File(templateBasePath));
/* 281 */       cfg.setObjectWrapper(new DefaultObjectWrapper());
/* 282 */       if ("Y".equals(sqlMapperFlag)) {
/* 283 */         FreemarkerEngine.createFileByFTL(cfg, root, "sqlmap.ftl", pathSrc, sqlMapperPath);
/*     */       }
/* 285 */       if ("Y".equals(domainFlag)) {
/* 286 */         FreemarkerEngine.createFileByFTL(cfg, root, "domainClass.ftl", pathSrc, domainPath);
/*     */       }
/* 288 */       if ("Y".equals(daoFlag)) {
/* 289 */         FreemarkerEngine.createFileByFTL(cfg, root, "daoClass.ftl", pathSrc, daoPath);
/*     */       }
/* 291 */       if ("Y".equals(daoImplFlag)) {
/* 292 */         FreemarkerEngine.createFileByFTL(cfg, root, "daoImplClass.ftl", pathSrc, daoImplPath);
/*     */       }
/* 294 */       if ("Y".equals(serviceFlag)) {
/* 295 */         FreemarkerEngine.createFileByFTL(cfg, root, "serviceClass.ftl", pathSrc, servicePath);
/*     */       }
/* 297 */       if ("Y".equals(serviceImplFlag)) {
/* 298 */         FreemarkerEngine.createFileByFTL(cfg, root, "serviceImplClass.ftl", pathSrc, serviceImplPath);
/*     */       }
/* 300 */       if ("Y".equals(controllerFlag)) {
/* 301 */         FreemarkerEngine.createFileByFTL(cfg, root, "controllerClass.ftl", pathSrc, controllerPath);
/*     */       }
/* 303 */       if ("Y".equals(pageFlag)) {
/* 304 */         FreemarkerEngine.createFileByFTL(cfg, root, "pageIndex.ftl", pathSrc, pageIndexPath);
/* 305 */         FreemarkerEngine.createFileByFTL(cfg, root, "pageAdd.ftl", pathSrc, pageAddPath);
/* 306 */         FreemarkerEngine.createFileByFTL(cfg, root, "pageDetail.ftl", pathSrc, pageDetailPath);
/* 307 */         FreemarkerEngine.createFileByFTL(cfg, root, "pageEdit.ftl", pathSrc, pageEditPath);
/*     */       }
/* 309 */       if ("Y".equals(domainQueryFlag)) {
/* 310 */         FreemarkerEngine.createFileByFTL(cfg, root, "domainQueryClass.ftl", pathSrc, domainQueryPath);
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 315 */       log.info("----------------------------代码生成完毕---------------------------");
/* 316 */       System.out.println("----------------------------代码生成完毕---------------------------");
/*     */     } catch (Exception e1) {
/* 318 */       e1.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getProjectPath()
/*     */   {
/* 330 */     String path = System.getProperty("user.dir").replace("\\", "/") + "/";
/* 331 */     return path;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getClassPath()
/*     */   {
/* 339 */     String path = new CodeGenerateFactory().getClass().getResource("/").getPath();
/* 340 */     return path;
/*     */   }
/*     */ }


/* Location:              /Users/guo/.m2/repository/org/jeewxframework/P3-Codegenerate/2.0.1/P3-Codegenerate-2.0.1.jar!/org/jeecgframework/p3/cg/factory/CodeGenerateFactory.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */